<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>退款请求</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="../plugins/layui/css/layui.css" media="all" />
		<link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
	</head>

	<body>
		<div style="margin: 15px;">
			<blockquote class="layui-elem-quote">
				<a href="javascript:history.go(-1);;" class="layui-btn layui-btn-small" id="add">
					<i class="layui-icon">&#xe608;</i> 返回
				</a>
			</blockquote>

			<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
				<legend>退款请求信息</legend>
			</fieldset>

			<form class="layui-form"  action="">
				<div id="content">

				</div>
			</form>
		</div>

		<!--模板-->
		<script type="text/html" id="tpl">
			<% for(var i=0;i<1;i++){ %>
        <div class="layui-form-item">
          <label class="layui-form-label">id</label>
          <div class="layui-input-inline">
            <input type="tel" value="<%==result.rfid %>" disabled="true" name="phone" lay-verify="phone" autocomplete="off" class="layui-input">
          </div>
        </div>
			<div class="layui-form-item">
				<label class="layui-form-label">退款金额</label>
				<div class="layui-input-block">
					<input type="text" value="<%==result.refundFee %>" disabled="true" name="title" lay-verify="title" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">退款原因</label>
				<div class="layui-input-block">
					<input type="text" value="<%==result.refundReason %>" disabled="true" name="username" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
				</div>
			</div>
      <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <%
        var state ;
        if(result.shopCart.ordersState==5){
          state = "未处理";
        }else if(result.shopCart.ordersState==6){
          state = "已同意";
        }else if(result.shopCart.ordersState==8){
          state = "已拒绝";
        }
        %>
        <div class="layui-input-block">
          <input type="text" value="<%==state %>" disabled="true" name="username" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
      </div>
			<div class="layui-form-item">
				<label class="layui-form-label">退款单号</label>
				<div class="layui-input-inline">
					<input type="tel" value="<%==result.refundNum %>" disabled="true" name="phone" lay-verify="phone" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">退款账号</label>
				<div class="layui-input-inline">
					<input type="text" value="<%==result.buyerLogonId %>" disabled="true" name="email" lay-verify="email" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">请求时间</label>
				<div class="layui-input-inline">
					<input type="text" value="<%==result.refundRequestTime %>" disabled="true" name="email" lay-verify="email" autocomplete="off" class="layui-input">
				</div>
			</div>
      <% if(result.refuseReason!=null){ %>
			<div class="layui-form-item">
				<label class="layui-form-label">拒绝原因</label>
				<div class="layui-input-block">
					<input type="text" value="<%==result.refuseReason %>" disabled="true" name="email" lay-verify="email" autocomplete="off" class="layui-input">
				</div>
			</div>
      <%}%>
      <% if(result.refundTime!=null){ %>
			<div class="layui-form-item">
				<label class="layui-form-label">退款时间</label>
				<div class="layui-input-inline">
					<input type="text" value="<%==result.refundTime %>" disabled="true" name="email" lay-verify="email" autocomplete="off" class="layui-input">
				</div>
			</div>

      <%}else{%>
        <div class="layui-form-item">
        <div class="layui-input-block">
          <% if(result.shopCart.ordersState==5){%>
          <input type="button" class="layui-btn" onclick="agreeRefund()" value="同意请求" >
          <%}%>
          <% if(result.shopCart.ordersState!=8){%>
          <input type="button" class="layui-btn layui-btn-primary" onclick="refuseRefund()" value="拒绝请求" >
          <%}%>
        </div>
      </div
      <%}%>

			<%}%>
		</script>

		<script type="text/javascript" src="../plugins/layui/layui.js"></script>
		<script type="text/javascript" src="../js/jquery.min.js"></script>
		<script type="text/javascript" src="../js/template.js"></script>
		<script type="text/javascript" src="../js/publish.js"></script>
		<script type="text/javascript" src="../js/jquery.min.js"></script>
		<script>
			var data;
			var spid = getUrlParam("spid");
      var rfid;
			$.ajax({
				url: '/admin/refund//get_sp/'+spid,
				dataType: 'json',
				async: false,
				success: function(response) {
					if(response.code == 200) {
						data = response;
            rfid = data.result.rfid;
					}
				}
			});

      layui.use(['layer'], function() {
					var layer = layui.layer;
			});
			var html = template('tpl', data);
			document.getElementById('content').innerHTML = html;

      function agreeRefund(){
        layer.open({
  				content: '你确定要同意退款么?',
  				btn: ['确定', '取消'],
  				yes: function(index, layero) {
  					//按钮【按钮一】的回调
  					$.ajax({
  						url: '/admin/refund/do_ref/'+rfid,
  						dataType: 'json',
              data:{
                isAgree:true,
              },
  						async: false,
  						success: function(response) {
  							layer.close(index);
  							if (response.code == 200) {
  								toast("请求成功");
  							} else {
  								toast("请求失败");
  							}
  						}
  					});

  				}
  			});
      }

      function refuseRefund() {
  			layer.open({
  				title: "拒绝退款",
  				content: '<input type="text" id="refuseReason" value=""  lay-verify="required" autocomplete="off"  class="layui-input">',
  				btn: ['确定', '取消'],
  				yes: function(index, layero) {
  					$.ajax({
  						url: '/admin/refund/do_ref/'+rfid,
              data:{
                isAgree:false,
                refuseReason:document.getElementById("refuseReason").value,
              },
  						dataType: 'json',
  						async: false,
  						success: function(response) {
  							layer.close(index);
  							if (response.code == 200) {
  								toast("请求成功");
  								location.reload();
  							} else {
  								toast("请求失败");
  							}
  						}
  					});

  				}
  			});
  		}

			</script>
	</body>

</html>
